package cn.com.qingz.core.utils;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumQueryRequest;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.request.AlibabaAliqinFcTtsNumSinglecallRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumQueryResponse;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import com.taobao.api.response.AlibabaAliqinFcTtsNumSinglecallResponse;

/**
 * Created by Administrator on 2016-03-01.
 */
public class AliSMSUtils {


    private static String AK = "23318792" ;
    private static String SK = "7c7ad26dad5272ee38880243bb6796d1" ;

    public static void main(String[] args) throws Exception {
//
//        String url = "http://gw.api.taobao.com/router/rest" ;
//        TaobaoClient client = new DefaultTaobaoClient(url, AK, SK);
//        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
//        //	公共回传参数，在“消息返回”中会透传回该参数；举例：用户可以传入自己下级的会员ID，在消息返回时，该会员ID会包含在内，用户可以根据该会员ID识别是哪位会员使用了你的应用
//        req.setExtend("123456");
//        req.setSmsType("normal");
//        req.setSmsFreeSignName("注册验证");//短信签名
//
//        //短信模板变量，传参规则{"key":"value"}，key的名字须和申请模板中的变量名一致，多个变量之间以逗号隔开。示例：针对模板“验证码${code}，
//        // 您正在进行${product}身份验证，打死不要告诉别人哦！”，传参时需传入{"code":"1234","product":"alidayu"}
//        //验证码${code}，您正在注册成为${product}用户，感谢您的支持！
//
//        req.setSmsParamString("{\"code\":\"2354125\",\"product\":\"来配机\"}");
//        req.setRecNum("18030802552");//接收者号码 可以逗号隔开
//        req.setSmsTemplateCode("SMS_5400255");//短信模版ID
//        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
//        System.out.println(rsp.getBody());
          sendValidCode("18030802552" , "1514365","来设计");
    }


    public static void sendValidCode(String phone , String code ,String name) throws Exception {
        String url = "http://gw.api.taobao.com/router/rest" ;
        TaobaoClient client = new DefaultTaobaoClient(url, AK, SK);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        //	公共回传参数，在“消息返回”中会透传回该参数；举例：用户可以传入自己下级的会员ID，在消息返回时，该会员ID会包含在内，用户可以根据该会员ID识别是哪位会员使用了你的应用
        req.setSmsType("normal");
        req.setSmsFreeSignName("注册验证");//短信签名
        req.setSmsParamString("{\"code\":\"" +code+"\",\"product\":\""+name+"\"}");
        req.setRecNum(phone);//接收者号码 可以逗号隔开
        req.setSmsTemplateCode("SMS_5400255");//短信模版ID
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }






    public static void sendTest() throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "23298798", "76580ef6f4dfa48787de7ec503486440");
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setSmsType("normal");
        req.setSmsParam("{\"product\":\"快捷取款\",\"code\":\"1234\"}");
        req.setSmsFreeSignName("身份验证");
        req.setRecNum("15828240910,18180463800");
        req.setSmsTemplateCode("SMS_4450976");
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void query() throws ApiException{
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "23298798", "76580ef6f4dfa48787de7ec503486440");
        AlibabaAliqinFcSmsNumQueryRequest req = new AlibabaAliqinFcSmsNumQueryRequest();
        req.setRecNum("15828240910");
        req.setQueryDate("20160114");
        req.setCurrentPage(1L);
        req.setPageSize(10L);
        AlibabaAliqinFcSmsNumQueryResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static void call() throws ApiException{
        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "23298798", "76580ef6f4dfa48787de7ec503486440");
        AlibabaAliqinFcTtsNumSinglecallRequest req = new AlibabaAliqinFcTtsNumSinglecallRequest();
        req.setTtsParamString("{\"product\":\"测试注册\",\"code\":\"111验证码\"}");
        req.setCalledNum("15828240910,13699423206");
        req.setTtsCode("TTS_4450983");
        req.setCalledShowNum("4001112222");
        AlibabaAliqinFcTtsNumSinglecallResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }


}
